<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Vue 中的样式绑定</title>
    <script src="js/vue.js"></script>
    <style>
        .activated {
            color: red;
        }
        .blue {
            color: blue;
        }
    </style>
</head>
<body>
    <div id="app">
        <div @click="handleDivClick" :class="{activated: isActivated}">hello world</div>
        <div @click="handleDivClick2" :class="[activated2]">hello world</div>
        <div @click="handleDivClick3" :style="styleObj">hello world</div>
        <div @click="handleDivClick3" :style="[styleObj,styleObj2]">hello world</div>
    </div>
    <script>
        var vm = new Vue({
            el: "#app",
            data: {
                isActivated: false,
                activated2: "",
                styleObj: {
                    color: "green"
                },
                styleObj2: {
                    fontSize: "30px"
                }
            },
            methods: {
                handleDivClick: function () {
                    this.isActivated = !this.isActivated;
                },
                handleDivClick2: function () {
                    // 三元表达式
                    this.activated2 = this.activated2 === "blue" ? "" : "blue"

                },
                handleDivClick3: function () {
                    this.styleObj.color = this.styleObj.color === "black" ? "red" : "black"
                }
            }
        })
    </script>
</body>
</html>